import React, { lazy } from "react";
import Top from "@/views/Layout/Top";
import Login from "@/views/Login";
import Register from "@/views/Login/RegisterForm";
import Findpwd from "@/views/Login/FindPwdForm";
import SkeletonLoading from "@/views/SkeletonLoading";
import { Navigate } from "react-router-dom";
import { routesType } from "@/types/route";

const Error404 = lazy(() => import("@/views/Error/404"));
const Monitor = lazy(() => import("@/views/monitor"));
const Dispatch = lazy(() => import("@/views/dispatch"));
const Right = lazy(() => import("@/views/system/right"));
const User = lazy(() => import("@/views/system/user"));
const Request = lazy(() => import("@/views/system/request"));
const Rewards = lazy(() => import("@/views/system/rewards"));
const Bike = lazy(() => import("@/views/system/bike"));
const Model = lazy(() => import("@/views/model"));
const ModelTestLog = lazy(() => import("@/views/model/modelTest"));
const Operation = lazy(() => import("@/views/statistics/operation"));
const Feedback = lazy(() => import("@/views/statistics/feedback"));
const Home = lazy(() => import("@/views/Home"));

const withLoadingComponent = (Comp: JSX.Element) => (
  <React.Suspense fallback={<SkeletonLoading />}>{Comp}</React.Suspense>
);
const routes: routesType[] = [
  {
    path: "/",
    element: <Navigate to="/home" />,
  },
  {
    path: "*",
    element: <Navigate to="/404" />,
  },
  {
    path: "/404",
    element: <Error404 />,
  },
  {
    path: "/login",
    element: <Login />,
  },
  {
    path: "/findpwd",
    element: <Findpwd />
  },
  {
    path: "/register",
    element: <Register />
  },
  {
    path: "/",
    element: <Top />,
    exact: true,
    name: "menuRoutes",
    children: [
      {
        path: "/home",
        element: withLoadingComponent(<Home />),
      },
      {
        path: "/monitor",
        element: withLoadingComponent(<Monitor />),
        meta: {
          title: "监控管理",
        },
      },
      {
        path: "/dispatch",
        element: withLoadingComponent(<Dispatch />),
        meta: {
          title: "调度管理",
        },
      },
      {
        path: "/model",
        meta: {
          title: "模型管理",
        },
        children: [
          {
            path: "/model/display",
            element: withLoadingComponent(<Model />),
            meta: {
              title: "模型列表"
            }
          },
          {
            path: "/model/testLog",
            element: withLoadingComponent(<ModelTestLog />),
            meta: {
              title: "测试记录"
            }
          }
        ]
      },
      {
        path: "/system",
        meta: {
          title: "系统管理",
        },
        children: [
          {
            path: "/system/right",
            element: withLoadingComponent(<Right />),
            meta: {
              title: "权限管理",
            },
          },
          {
            path: "/system/user",
            element: withLoadingComponent(<User />),
            meta: {
              title: "用户管理",
            },
          },
          {
            path: "/system/request",
            element: withLoadingComponent(<Request />),
            meta: {
              title: "请求管理",
            },
          },
          {
            path: "/system/rewards",
            element: withLoadingComponent(<Rewards />),
            meta: {
              title: "奖励管理",
            },
          },
          {
            path: "/system/bike",
            element: withLoadingComponent(<Bike />),
            meta: {
              title: "单车管理",
            },
          },
        ],
      },
      {
        path: "/statistics",
        meta: {
          title: "统计管理",
        },
        children: [
          {
            path: "/statistics/operation",
            element: withLoadingComponent(<Operation />),
            meta: {
              title: "操作日志",
            },
          },
          {
            path: "/statistics/feedback",
            element: withLoadingComponent(<Feedback />),
            meta: {
              title: "用户反馈",
            },
          },
        ],
      },
    ],
  },
];

export default routes;
